package wechat.service.controller;

import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import wechat.service.common.SwitchResources;

@Controller
@RequestMapping("/CenterService")
public class CenterServiceController {

	private Logger log = LoggerFactory.getLogger(CenterServiceController.class);

	/**
	 * 前置服务
	 * 
	 * 
	 * @throws IOException 
	 */
	@GetMapping
	public void centerService(HttpServletRequest request, HttpServletResponse response) throws IOException {

		String userAgent = request.getHeader("User-Agent");
		String state = request.getParameter("state");
		String payCode = request.getParameter("payCode");
		String appid = request.getAttribute("appid").toString();

		log.info("CenterServiceServlet Get userAgent=" + userAgent);
		log.info("CenterServiceServlet Get appid=" + appid + " state=" + state);

		String url = SwitchResources.getUrlResources(appid, state, userAgent);

		log.info("CenterServiceServlet Get url=" + url);
		if ("".equals(url)) {
			return;
		}

		response.sendRedirect(url);
	}

}
